package com.inxedu.os.edu.service.emil.impl;

import com.inxedu.os.edu.dao.EduEmailsendHistoryMapper;

import com.inxedu.os.edu.dao.EduUserMapper;
import com.inxedu.os.edu.dao.SysUserMapper;
import com.inxedu.os.edu.pojo.*;
import com.inxedu.os.edu.service.emil.AdminEmailMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AdminEmailMsgImpl implements AdminEmailMsg {
    @Autowired
    private EduEmailsendHistoryMapper emailmapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private EduUserMapper userMapper;
//    @Override
//    public List<EduEmailsendHistoryAndLoginname> selectAll() {
//        List<EduEmailsendHistoryAndLoginname> selectAll = emailmapper.selectAll();
//        return selectAll;
//    }
    //查询邮件管理
    @Override
    public List<EduEmailsendHistoryAndLoginname> GetEmailByExample(UserEmailMsg userEmailMsg) {
        List<EduEmailsendHistoryAndLoginname> eduEmailsendHistoryAndLoginnames = emailmapper.selectBykey(userEmailMsg);
        return eduEmailsendHistoryAndLoginnames;
    }
    //发送邮件
    @Override
    public EduEmailsendHistoryAndLoginname GetEmailByid(Integer id) {
        EduEmailsendHistoryWithBLOBs eduemil = emailmapper.selectByPrimaryKey(id);
        Integer userId = eduemil.getUserId();
        SysUser user = sysUserMapper.selectByPrimaryKey(userId);
        String loginName = user.getLoginName();
        EduEmailsendHistoryAndLoginname edu=new EduEmailsendHistoryAndLoginname();
        edu.setLoginName(loginName);
        edu.setContent(eduemil.getContent());
        edu.setCreateTime(eduemil.getCreateTime());
        edu.setEmail(eduemil.getEmail());
        edu.setId(id);
        edu.setStatus(eduemil.getStatus());
        edu.setSendTime(eduemil.getSendTime());
        edu.setTitle(eduemil.getTitle());
        edu.setType(eduemil.getType());
        edu.setUserId(userId);
        return edu;
    }
    //发送邮件
    @Override
    public int addEmail(EduEmailsendHistoryWithBLOBs bloBs) {
        int insert = emailmapper.insert(bloBs);
        return insert;
    }

    @Override
    public List<EduUser> getUserList() {
        EduUserExample example = new EduUserExample();
     /*   EduUserExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdIsNotNull();*/
        List<EduUser> users = userMapper.selectByExample(example);
        return users;
    }

}
